#include "DiolPOV.h"

#include <assert.h>
#include <sstream>

namespace Diol
{

POV::POV( const ObjectInstance& objectInstance, Device* parentDevice )
  : Object( objectInstance, parentDevice ), 
    mAngle(0), 
	mIsCentered(true)
{
	assert( objectInstance.isPOV() );		
}

std::string POV::toString() const
{
	std::stringstream str;
	str << "POV Id:" << getObjectInstance().getDwType();
	if ( isCentered() )
		str << " Value:Centered";
	else 
		str << " Value:Not centered " << " Angle:" << getAngle();
	str << " Name:'" << getObjectInstance().getName() << "'";
	return str.str();
}

DWORD POV::getAngle() const					
{ 
	assert( !isCentered() );
	if ( isCentered() ) 
		return 0;
	return mAngle; 
}

void POV::updateFrom( const DIDEVICEOBJECTDATA& entry )
{
	if ( LOWORD(entry.dwData)==0xFFFF )
		setValue( true, 0 );
	else 
		setValue( false, entry.dwData );
}

void POV::setValue( bool isCentered, DWORD angle )
{
	assert( (!isCentered) || ( isCentered && angle==0) );
	assert( angle>=0 && angle<=35999 );
	if ( isCentered==mIsCentered && angle==mAngle )
		return;
	mIsCentered = isCentered;
	mAngle = angle;
	notifyChanged();
}


}
